package com.ruoyi.web.controller.workJob;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.worker.domain.Company;
import com.ruoyi.worker.domain.TimeShift;
import com.ruoyi.worker.service.CompanyService;
import com.ruoyi.worker.service.TimeShiftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @ClassName TimeShiftApi
 * @Description
 * @Author leizhang
 * Date 2021/8/29 1:45 下午
 * @Version 1.0
 **/
@RestController
@RequestMapping("/timeShiftApi")
public class TimeShiftApi extends BaseController {

    @Autowired
    private TimeShiftService timeShiftService;

    @GetMapping("/listTimeShiftList")
    public TableDataInfo getCompanyListInfo(TimeShift company){
        startPage();
        List<TimeShift> companyList = timeShiftService.getTimeShiftList(company);
        return getDataTable(companyList);
    }

    //  @PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody Map<String, Object> requestParam) {
        return toAjax(timeShiftService.updateStatus(requestParam));
    }

    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody TimeShift timeShift) {
        return toAjax(timeShiftService.insertTimeShift(timeShift));
    }

    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @GetMapping("/getTimeShift/{id}")
    public AjaxResult getCompany(@PathVariable int id) {
        return  AjaxResult.success(timeShiftService.getTimeShift(id));
    }

    @Log(title = "班次管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public AjaxResult delCompany(@PathVariable int id) {
        return  toAjax(timeShiftService.deleteTimeShift(id));
    }

    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult update(@RequestBody TimeShift timeShift) {
        return  toAjax(timeShiftService.updateTimeShift(timeShift));
    }

    @Log(title = "班次管理", businessType = BusinessType.UPDATE)
    @PostMapping("/saveNumber")
    public AjaxResult saveNumber(@RequestBody Map<String,Object> requestParam) throws Exception {
        return  toAjax(timeShiftService.saveNumber(requestParam));
    }
}
